home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SCRIPT.PAK / ED_EPSLN.SPP < prev    next >
Text File  |  1997-05-06  |  40KB  |  1,538 lines

  1. //----------------------------------------------------------------------------
  2. // cScript
  3. // (C) Copyright 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. // ED_EPSLN.SPP
  6. //    Script component of IDE's Editor Epsilon emulation.
  7. //    Provides support services for editing environment.
  8. //
  9. // $Revision:   1.19  $
  10. //
  11. //----------------------------------------------------------------------------
  12. // Epsilon Editor.
  13. //----------------------------------------------------------------------------
  14.  
  15. //----------------------------------------------------------------------------
  16. // Symbol Imports
  17. //----------------------------------------------------------------------------
  18.  
  19. import IDE;
  20. import editor;
  21. import scriptEngine;
  22. import bFileLoading;
  23. import bPopEditorKeyboard;
  24.  
  25. //
  26. // Mark this module as being a library module.
  27. //
  28. library;
  29.  
  30. //----------------------------------------------------------------------------
  31. // Symbol Defines
  32. //----------------------------------------------------------------------------
  33.  
  34. #define BOOKMARK_ID_SYSTEM_ONE   19
  35. #define BOOKMARK_ID_SYSTEM_TWO   18
  36. #define BOOKMARK_ID_SYSTEM_THREE 17
  37. #define FUNCTION_CONTINUE 0
  38. #define FUNCTION_END      1
  39.  
  40. //----------------------------------------------------------------------------
  41. // Menu Vectors.
  42. //----------------------------------------------------------------------------
  43.  
  44. DoIDEFileClose()      { return FUNCTION_CONTINUE; }
  45. DoIDEFileOpen()       { return FUNCTION_CONTINUE; }
  46. DoIDEFilePrint()      { return FUNCTION_CONTINUE; }
  47. DoIDEFileSave()       { return FUNCTION_CONTINUE; }
  48. DoIDEFileSaveAs()     { return FUNCTION_CONTINUE; }
  49. DoIDEFileSaveAll()    { return FUNCTION_CONTINUE; }
  50.  
  51. DoIDEEditUndo()       { editor.Undo(); return FUNCTION_END; }
  52. DoIDEEditRedo()       { editor.Redo(); return FUNCTION_END; }
  53. DoIDEEditCut()        { editor.EmacsAppendNextMenuKillStart(); editor.EmacsKillRegion(); editor.EmacsAppendNextMenuKillEnd(); return FUNCTION_END; }
  54. DoIDEEditCopy()       { editor.EmacsCopyRegion(); return FUNCTION_END;  }
  55. DoIDEEditPaste()      { editor.EmacsYank(); return FUNCTION_END; }
  56. DoIDEEditClear()      { editor.EmacsAppendNextMenuKillStart(); editor.EmacsKillRegion(); editor.EmacsAppendNextMenuKillEnd(); return FUNCTION_END; }
  57. DoIDEEditSelectAll()  { editor.SelectAll(); return FUNCTION_END; }
  58. DoIDEEditBufferList() { return FUNCTION_CONTINUE; }
  59.  
  60. DoIDESearchFind()     { editor.EmacsSetSearch(); return FUNCTION_CONTINUE; }
  61. DoIDESearchReplace()  { editor.EmacsSetReplace(); return FUNCTION_CONTINUE; }
  62. DoIDESearchSearchAgain() { return FUNCTION_CONTINUE; }
  63.  
  64. DoIDESearchPreviousMessage() { return FUNCTION_CONTINUE; }
  65. DoIDESearchNextMessage()     { return FUNCTION_CONTINUE; }
  66.  
  67. //----------------------------------------------------------------------------
  68. // Methods.
  69. //----------------------------------------------------------------------------
  70.  
  71. //
  72. // Used to autoload the Default emulation specific methods.
  73. //
  74. epsilonEmulation(bUnassign) {
  75.  
  76.    IDE.KeyboardManager.ScriptAbortKey = "<Ctrl-g>";
  77.    IDE.KeyboardManager.ProcessKeyboardAssignments(scriptEngine.StartupDirectory+IDE.KeyboardAssignmentFile,bUnassign);
  78.  
  79.    if (bUnassign) {
  80.       print "Epsilon emulation removed.";
  81.       scriptEngine.Unload(typeid(module()));
  82.    } else {
  83.       print "Epsilon emulation enabled.";
  84.    }
  85. }
  86.  
  87. //----------------------------------------------------------------------------
  88. // EPSILON Editor.
  89. //----------------------------------------------------------------------------
  90.  
  91. #define EMACS_MARK BOOKMARK_ID_SYSTEM_THREE
  92. #define EMACS_MAXIMUM_KILL_BUFFERS 10
  93.  
  94. class EmacsSubsystem {
  95.  
  96.    LoadMateFunctionality();
  97.  
  98.    // Buffer variables.
  99.    declare nClipboardToken = 0;
  100.    declare nKeysProcessedKill = -1;
  101.    declare nKeysProcessedYankPop = -1;
  102.    declare nKeysProcessedYank = -1;
  103.    declare nKillBufferIndex = -1;
  104.    declare nKillBufferCount = 0;
  105.    declare array aKillBuffers[EMACS_MAXIMUM_KILL_BUFFERS+1];
  106.  
  107.    // Blocking variables.
  108.    declare bTransparent = FALSE;
  109.  
  110.    // Direction Variable
  111.    declare nPreferredColumn = 1;
  112.  
  113.    // Argument Variables
  114.    declare nArgument = 0;
  115.    declare nKeysEntered = 0;
  116.    declare acCommand = NULL;
  117.  
  118.    // Keyboards
  119.    declare kbdEditor = NULL;
  120.    declare kbdEscape = NULL;
  121.    declare kbdCarrot = NULL;
  122.    declare kbdArgument = NULL;
  123.  
  124.    // Subsystem Methods
  125.    StepKillBufferIndex() {
  126.  
  127.       if (nKillBufferCount != EMACS_MAXIMUM_KILL_BUFFERS)
  128.          nKillBufferCount++;
  129.  
  130.       if (nKillBufferIndex == nKillBufferCount)
  131.          nKillBufferIndex = 0;
  132.       else
  133.          nKillBufferIndex++;
  134.    }
  135.  
  136.    BackKillBufferIndex() {
  137.       if (nKillBufferIndex)
  138.          nKillBufferIndex--;
  139.       else
  140.          nKillBufferIndex = nKillBufferCount;
  141.    }
  142.  
  143.    SetKillBufferContents(declare acContents, declare ep, declare bReverse) {
  144.       if (nKeysProcessedKill == IDE.KeyboardManager.KeysProcessed - 1 &&
  145.          nKillBufferCount) {
  146.          // Append to the current kill buffer
  147.          declare nIndex = nKillBufferIndex;
  148.          if (bReverse)
  149.             aKillBuffers[nIndex] = new String(acContents + aKillBuffers[nIndex].Text);
  150.          else
  151.             aKillBuffers[nIndex] = new String(aKillBuffers[nIndex].Text + acContents);
  152.             if (ep != NULL)
  153.                ep.SetClipboard(aKillBuffers[nIndex].Text);
  154.       } else {
  155.          StepKillBufferIndex();
  156.          aKillBuffers[nKillBufferIndex] = new String(acContents);
  157.          if (ep != NULL)
  158.             ep.SetClipboard(aKillBuffers[nKillBufferIndex].Text);
  159.       }
  160.       nKeysProcessedKill = IDE.KeyboardManager.KeysProcessed;
  161.    }
  162.  
  163.    YankKillBufferContents(declare ep, declare popBuffer) {
  164.       if (popBuffer)
  165.          BackKillBufferIndex();
  166.       if (nKillBufferIndex > -1) {
  167.           if (initialized(aKillBuffers[nKillBufferIndex])) {
  168.              declare aString = aKillBuffers[nKillBufferIndex];
  169.              ep.SetClipboard(aString.Text);
  170.              nClipboardToken = ep.GetClipboardToken();
  171.              return aString.Text;
  172.           }
  173.       }
  174.       // just in case they yank without ever having killed
  175.       return "";
  176.    }
  177. };
  178.  
  179. //
  180. // Instantiate the EmacsSubsystem class.
  181. //
  182. export declare EmacsSubsystem ess;
  183.  
  184. on editor:>Append() {
  185.    declare eb = .BlockExists();
  186.  
  187.    if (eb != NULL) {
  188.       declare ep = .TopView.Position;
  189.       eb.Save();
  190.       ep.Move(eb.StartingRow,eb.StartingColumn);
  191.       ep.InsertScrap();
  192.       ep.Move(eb.StartingRow,eb.StartingColumn);
  193.       eb.Restore();
  194.       eb.Cut();
  195.    } else
  196.       IDE.ReportError("No marked block");
  197. }
  198.  
  199. //
  200. // The next kill operations should append.
  201. //
  202. on editor:>EmacsAppendNextKill()
  203. {
  204.    ess.nKeysProcessedKill = IDE.KeyboardManager.KeysProcessed;
  205. }
  206.  
  207. //
  208. // The next kill operations should append if appending has been set and the menu is used.
  209. //
  210. on editor:>EmacsAppendNextMenuKillStart()
  211. {
  212.    if (ess.nKeysProcessedKill == IDE.KeyboardManager.KeysProcessed) 
  213.        ess.nKeysProcessedKill = IDE.KeyboardManager.KeysProcessed-1;
  214. }
  215.  
  216. //
  217. // The next kill operations should no longer append if appending has been set and the menu is used.
  218. //
  219. on editor:>EmacsAppendNextMenuKillEnd()
  220. {
  221.    if (ess.nKeysProcessedKill == IDE.KeyboardManager.KeysProcessed-1) 
  222.        ess.nKeysProcessedKill = IDE.KeyboardManager.KeysProcessed-2;
  223. }
  224.  
  225. //
  226. // The next operation should use this argument.
  227. //
  228. on editor:>EmacsArgument(declare nAmount)
  229. {
  230.    if (ess.kbdArgument == NULL) {
  231.       ess.kbdArgument = new Keyboard(FALSE);
  232.       declare kbd = ess.kbdArgument;
  233.       kbd.Assign("<1>","editor.EmacsArgumentKeyPress(1,FALSE);");
  234.       kbd.Assign("<2>","editor.EmacsArgumentKeyPress(2,FALSE);");
  235.       kbd.Assign("<3>","editor.EmacsArgumentKeyPress(3,FALSE);");
  236.       kbd.Assign("<4>","editor.EmacsArgumentKeyPress(4,FALSE);");
  237.       kbd.Assign("<5>","editor.EmacsArgumentKeyPress(5,FALSE);");
  238.       kbd.Assign("<6>","editor.EmacsArgumentKeyPress(6,FALSE);");
  239.       kbd.Assign("<7>","editor.EmacsArgumentKeyPress(7,FALSE);");
  240.       kbd.Assign("<8>","editor.EmacsArgumentKeyPress(8,FALSE);");
  241.       kbd.Assign("<9>","editor.EmacsArgumentKeyPress(9,FALSE);");
  242.       kbd.Assign("<Alt-1>","editor.EmacsArgumentKeyPress(1,TRUE);");
  243.       kbd.Assign("<Alt-2>","editor.EmacsArgumentKeyPress(2,TRUE);");
  244.       kbd.Assign("<Alt-3>","editor.EmacsArgumentKeyPress(3,TRUE);");
  245.       kbd.Assign("<Alt-4>","editor.EmacsArgumentKeyPress(4,TRUE);");
  246.       kbd.Assign("<Alt-5>","editor.EmacsArgumentKeyPress(5,TRUE);");
  247.       kbd.Assign("<Alt-6>","editor.EmacsArgumentKeyPress(6,TRUE);");
  248.       kbd.Assign("<Alt-7>","editor.EmacsArgumentKeyPress(7,TRUE);");
  249.       kbd.Assign("<Alt-8>","editor.EmacsArgumentKeyPress(8,TRUE);");
  250.       kbd.Assign("<Alt-9>","editor.EmacsArgumentKeyPress(9,TRUE);");
  251.       kbd.Assign("<Ctrl-u>","editor.EmacsArgumentKeyPress(0,TRUE);");
  252.       kbd.DefaultAssignment = "editor.EmacsArgumentDoAction();";
  253.    }
  254.  
  255.    if (initialized(nAmount))
  256.       ess.nArgument = nAmount;
  257.    else
  258.       ess.nArgument = 4;
  259.       
  260.    ess.nKeysEntered = 0;
  261.    ess.acCommand = NULL;
  262.    ess.kbdEditor = IDE.KeyboardManager.GetKeyboard("Editor");
  263.    IDE.KeyboardManager.Push(ess.kbdArgument, "Editor", FALSE);
  264.    bPopEditorKeyboard = true;
  265.    IDE.StatusBar = "Argument: " + ess.nArgument;
  266. }
  267.  
  268. on editor:>EmacsArgumentKeyPress(declare nAmount, declare bDirectValue) {
  269.    if (bDirectValue) {
  270.       if (nAmount == 0) {
  271.          ess.nArgument = ess.nArgument * 4;
  272.       } else {
  273.          ess.nArgument = nAmount;
  274.       }
  275.    } else {
  276.       declare String sValue(ess.nArgument);
  277.       declare String sAmount(nAmount);
  278.       declare String sTotal(sValue.Text + sAmount.Text);
  279.       ess.nArgument = sTotal.Integer;
  280.    }
  281.  
  282.    IDE.StatusBar = "Argument: " + ess.nArgument;
  283. }
  284.  
  285.  
  286. on editor:>EmacsArgumentDoAction() {
  287.  
  288.    declare km = IDE.KeyboardManager;
  289.  
  290.    if (ess.nKeysEntered < 2) {
  291.        ess.nKeysEntered++;
  292.        declare String sCommand(ess.kbdEditor.GetCommand(km.CodeToKey(km.LastKeyProcessed)));
  293.        if (sCommand.Length)
  294.           ess.acCommand = sCommand;
  295.        else {
  296.           if (km.LastKeyProcessed < 128) {
  297.            declare k = new String();
  298.            k.Character = km.LastKeyProcessed;
  299.            ess.acCommand = k;
  300.           }
  301.        }
  302.   }
  303.  
  304.    if (ess.acCommand != NULL) {
  305.       declare nIndex = 0;
  306.       if (ess.acCommand.Length == 1)
  307.          ess.acCommand = new String("editor.TopView.Position.InsertText(\""+ess.acCommand.Text+"\");");
  308.       for (nIndex = 0;nIndex < ess.nArgument; nIndex++) {
  309.          scriptEngine.Execute(ess.acCommand.Text);
  310.       }
  311.       ess.nKeysEntered = 2;
  312.    }
  313.  
  314.    if (ess.nKeysEntered > 1) {
  315.       km.Pop("Editor");
  316.       bPopEditorKeyboard = false;
  317.       IDE.StatusBar = "";
  318.    }
  319. }
  320.  
  321. on editor:>EmacsBackwardCharacter(declare withDelete) {
  322.    declare ep = .TopView.Position;
  323.  
  324.    if (ep.Column == 1 && ep.Row != 1) {
  325.       .ModalMoveRelative(-1, 0);
  326.       .ModalMoveEOL();
  327.    } else {
  328.       .ModalMoveRelative(0, -1);
  329.    }
  330.  
  331.    if (withDelete)
  332.       ep.Delete(1);
  333.  
  334.    ess.nPreferredColumn = ep.Column;
  335. }
  336.  
  337. //
  338. // Move the point backward to the previous tab stop.
  339. //
  340. on editor:>EmacsBackToTabStop() {
  341.    declare nDistance = .TopView.Position.DistanceToTab(SEARCH_BACKWARD);
  342.    .TopView.Position.MoveRelative(0,nDistance);
  343. }
  344.  
  345. //
  346. // Kill backwards one bracketed expression level.
  347. //
  348. on editor:>EmacsBackwardKillLevel() {
  349.    // Search for ')', '}' or ']'
  350.  
  351.    declare ep = .TopView.Position;
  352.    declare eb = .TopView.Block;
  353.  
  354.    ResetBlock(EXCLUSIVE_BLOCK);
  355.    EndBlock(EXCLUSIVE_BLOCK);
  356.  
  357.    declare nResult = ep.Search("[\]})]",TRUE,TRUE,SEARCH_BACKWARD);
  358.  
  359.    if (nResult) {
  360.       if (.MateQuiet(ep.Read(1), SEARCH_BACKWARD)) {
  361.          eb.Begin();
  362.          if (eb.Size) {
  363.             ess.SetKillBufferContents(eb.Text,ep,true);
  364.             RemoveBlock(eb);
  365.          }
  366.       }
  367.    }
  368.  
  369.    ResetBlock();
  370. }
  371.  
  372. //
  373. // Kill backwards one word.
  374. //
  375. on editor:>EmacsBackwardKillWord() {
  376.  
  377.    declare ep = .TopView.Position;
  378.    declare eb = .TopView.Block;
  379.  
  380.    ResetBlock(EXCLUSIVE_BLOCK);
  381.  
  382.    eb.End();
  383.    .EmacsBackwardWord();
  384.    eb.Begin();
  385.  
  386.    if (eb.Size) {
  387.       ess.SetKillBufferContents(eb.Text,ep,true);
  388.       RemoveBlock(eb);
  389.    }
  390. }
  391.  
  392. //
  393. // Move backwards one bracketed expression level.
  394. //
  395. on editor:>EmacsBackwardLevel() {
  396.    // Search for ')', '}' or ']'
  397.    declare bBlock = FALSE;
  398.    declare eb = .BlockExists();
  399.    declare ep = .TopView.Position;
  400.  
  401.    if (eb != NULL)
  402.       bBlock = TRUE;
  403.  
  404.    declare nResult = ep.Search("[\]})]",TRUE,TRUE,SEARCH_BACKWARD);
  405.  
  406.    if (nResult && .MateQuiet(ep.Read(1), SEARCH_BACKWARD) && bBlock)
  407.       eb.Begin();
  408. }
  409.  
  410. //
  411. // Move backwards one paragraph.
  412. //
  413. on editor:>EmacsBackwardParagraph() {
  414.  
  415.    declare bBlock = FALSE;
  416.    declare eb = .BlockExists();
  417.    declare ep = .TopView.Position;
  418.  
  419.    if (eb != NULL) {
  420.       bBlock = TRUE;
  421.    }
  422.  
  423.    if (ep.Column == 1 && ep.IsWhiteSpace)
  424.       ep.MoveRelative(-1,0);
  425.    else
  426.       ep.Move(0,1);
  427.  
  428.    while (ep.Row != 1) {
  429.       if (ep.IsWhiteSpace) {
  430.          break;
  431.       }
  432.       ep.MoveRelative(-1,0);
  433.    }
  434.  
  435.    if (bBlock) {
  436.       eb.Begin();
  437.    }
  438. }
  439.  
  440. //
  441. // Move backwards one paragraph.
  442. //
  443. on editor:>EmacsBackwardSentence() {
  444. }
  445.  
  446. //
  447. // Move backwards one word.
  448. //
  449. on editor:>EmacsBackwardWord() {
  450.    declare ep = .TopView.Position;
  451.    declare eb = .BlockExists();
  452.  
  453.    if (eb != NULL) {
  454.       ep.Save();
  455.       eb.Save();
  456.    }
  457.  
  458.    do {
  459.        ep.MoveCursor(SKIP_LEFT | SKIP_WHITE | SKIP_STREAM);
  460.        ep.MoveCursor(SKIP_LEFT | SKIP_NONWORD | SKIP_STREAM);
  461.        ep.MoveCursor(SKIP_LEFT | SKIP_WORD);
  462.    } while (!ep.IsWordCharacter && ep.Row != 1);
  463.  
  464.    if (eb != NULL) {
  465.       declare row = ep.Row;
  466.       declare column = ep.Column;
  467.       ep.Restore();
  468.       eb.Restore();
  469.       eb.Extend(row, column);
  470.    }
  471. }
  472.  
  473. //
  474. // Move to the beginning of the window.
  475. //
  476. on editor:>EmacsBeginningOfWindow() {
  477.    .ModalMoveViewTop();
  478.    .ModalMoveBOL();
  479. }
  480.  
  481. //
  482. // Move to the ending of the window.
  483. //
  484. on editor:>EmacsEndingOfWindow() {
  485.    .ModalMoveViewBottom();
  486.    .ModalMoveEOL();
  487. }
  488.  
  489. //
  490. // Summarize line information.
  491. //
  492. on editor:>EmacsCountLines() {
  493.    declare ep = .TopView.Position;
  494.  
  495.    declare String s(ep.Read());
  496.    declare ll =  ep.Column + s.Length - 3;
  497.  
  498.    IDE.StatusBar = "Lines = " + ep.LastRow +
  499.    " Line Number = " + ep.Row + " Line Length = " + ll;
  500. }
  501.  
  502. //
  503. // Summarize line information.
  504. //
  505. on editor:>EmacsCapitalizeWord() {
  506.    if (.BlockExists())
  507.       ResetBlock(EXCLUSIVE_BLOCK);
  508.  
  509.    if (!.TopView.Position.IsWordCharacter) {
  510.       .EmacsForwardWord();
  511.       .EmacsBackwardWord();
  512.    }
  513.  
  514.    BeginBlock(EXCLUSIVE_BLOCK);
  515.    .EmacsForwardCharacter();
  516.    declare eb = EndBlock();
  517.    eb.UpperCase();
  518.    if (.TopView.Position.IsWordCharacter) {
  519.       BeginBlock(EXCLUSIVE_BLOCK);             // implied call to Reset
  520.       .EmacsForwardWord();
  521.       eb = EndBlock();
  522.       eb.LowerCase();
  523.    }
  524.    ResetBlock(EXCLUSIVE_BLOCK);
  525. }
  526.  
  527. //
  528. // Copy the highlighted region to a kill buffer.
  529. //
  530. on editor:>EmacsCopyRegion() {
  531.  
  532.    ess.nKeysProcessedKill = 0;
  533.  
  534.    declare eb = .BlockExists();
  535.  
  536.    if (eb != NULL) {
  537.       ess.SetKillBufferContents(eb.Text,.TopView.Position,false);
  538.       CopyBlock(eb,false);
  539.    } else {
  540.       declare ev = .TopView;
  541.       declare ep = ev.Position;
  542.       eb = ev.Block;
  543.  
  544.       ep.Save();
  545.       eb.Begin();
  546.       ev.BookmarkGoto(EMACS_MARK);
  547.       eb.End();
  548.  
  549.       if (eb.Size) {
  550.          ess.SetKillBufferContents(eb.Text,ep,false);
  551.          CopyBlock(eb,false);
  552.       }
  553.       ep.Restore();
  554.       ResetBlock();
  555.    }
  556. }
  557.  
  558.  
  559. //
  560. // Using EMACS behaviour setup a keyboard to use the ctrl version of
  561. // the next key.
  562. //
  563. on editor:>EmacsCtrlPrefix()
  564. {
  565.    if (ess.kbdCarrot == NULL) {
  566.       ess.kbdCarrot = new Keyboard(FALSE);
  567.       ess.kbdCarrot.DefaultAssignment = "editor.EmacsCtrlPrefixKeyPress();";
  568.    }
  569.  
  570.    IDE.KeyboardManager.Push(ess.kbdCarrot, "Editor", FALSE);
  571.    bPopEditorKeyboard = true;
  572.    IDE.StatusBar = "<Ctrl>";
  573. }
  574.  
  575. on editor:>EmacsCtrlPrefixKeyPress() {
  576.  
  577.    declare km = IDE.KeyboardManager;
  578.    km.Pop("Editor");
  579.    bPopEditorKeyboard = false;
  580.    declare String sKey(km.CodeToKey(km.LastKeyProcessed));
  581.    declare nIndex = sKey.Index(">");
  582.    if (nIndex > 2)
  583.       sKey = sKey.SubString(1,nIndex-2);
  584.    sKey = "^" + sKey.Text;
  585.    km.SendKeys(sKey,TRUE);
  586. }
  587.  
  588.  
  589. //
  590. // Using EMACS behavior delete blank lines around the point.
  591. //
  592. on editor:>EmacsDeleteBlankLines() {
  593.  
  594.    declare ep = .TopView.Position;
  595.  
  596.    .TopView.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  597.  
  598.    if (ep.IsWhiteSpace || ep.Character == 13) {
  599.  
  600.        declare eb = .TopView.Block;
  601.  
  602.        ep.MoveCursor(SKIP_LEFT | SKIP_WHITE | SKIP_STREAM);
  603.  
  604.        if (ep.Column != 1)
  605.            ep.MoveRelative(1,0);
  606.  
  607.        declare nBeginingRow = ep.Row;
  608.  
  609.        ep.MoveBOL();
  610.  
  611.        ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE | SKIP_STREAM);
  612.  
  613.        if (!ep.IsWhiteSpace)
  614.            ep.MoveRelative(-1,0);
  615.  
  616.                  declare nEndingRow = ep.Row;
  617.  
  618.        if (nEndingRow == nBeginingRow) {
  619.            ep.Move(nBeginingRow,1);
  620.            eb.Begin();
  621.            ep.Move(nEndingRow+1,1);
  622.            eb.End();
  623.            eb.Delete();
  624.        } else {
  625.            ep.Move(nBeginingRow,1);
  626.            eb.Begin();
  627.            ep.Move(nEndingRow,1);
  628.            eb.End();
  629.            eb.Delete();
  630.        }
  631.    }
  632.  
  633.    .TopView.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  634. }
  635.  
  636. //
  637. // Using EMACS behavior delete the current word.
  638. //
  639. on editor:>EmacsDeleteWord() {
  640.    declare ep = .TopView.Position;
  641.    declare eb = .TopView.Block;
  642.  
  643.    ep.Save();
  644.  
  645.    BeginBlock(EXCLUSIVE_BLOCK);
  646.    .EmacsForwardWord();
  647.    EndBlock();
  648.    ess.SetKillBufferContents(eb.Text,ep,false);
  649.    RemoveBlock(eb);
  650.  
  651.    ep.Restore();
  652. }
  653.  
  654. on editor:>EmacsDeleteHorizontalSpace() {
  655.    declare ep = .TopView.Position;
  656.    declare eb = .TopView.Block;
  657.  
  658.    ResetBlock(EXCLUSIVE_BLOCK);
  659.    ep.MoveCursor(SKIP_LEFT | SKIP_WHITE);
  660.    BeginBlock(EXCLUSIVE_BLOCK);
  661.    ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
  662.    EndBlock();
  663.    RemoveBlock(eb,TRUE);
  664. }
  665.  
  666. on editor:>EmacsEnlargeWindow() {
  667.    IDE.SetWindowState(SW_MAXIMIZE);
  668. }
  669.  
  670. on editor:>EmacsEnlargeWindowHorizontal() {
  671. }
  672.  
  673. on editor:>EmacsForwardCharacter() {
  674.    declare ep = .TopView.Position;
  675.  
  676.    if (ep.Character == 13) {
  677.       .ModalMoveRelative(1, 0);
  678.       .ModalMoveBOL();
  679.    }
  680.    else {
  681.       .ModalMoveRelative(0,1);
  682.    }
  683.  
  684.  ess.nPreferredColumn = ep.Column;
  685. }
  686.  
  687. on editor:>EmacsForwardLevel() {
  688.    // must be on '(', '{' or '['
  689.    declare bBlock = FALSE;
  690.    declare eb = .BlockExists();
  691.    declare ep = .TopView.Position;
  692.    if (eb != NULL) {
  693.       bBlock = TRUE;
  694.    }
  695.  
  696.    declare nResult = ep.Search("[\]})]",TRUE,TRUE,SEARCH_FORWARD);
  697.  
  698.    if (nResult) {
  699.       if (.MateQuiet(ep.Read(1), SEARCH_FORWARD)) {
  700.          if (bBlock) {
  701.             eb.Begin();
  702.          }
  703.       }
  704.    }
  705. }
  706.  
  707. on editor:>EmacsForwardSentance() {
  708. }
  709.  
  710. on editor:>EmacsIndentRegion() {
  711.    // IndentBlock
  712.    declare eb = .BlockExists();
  713.    if (eb != NULL) {
  714.       eb.Indent(.Options.BlockIndent);
  715.    }
  716. }
  717.  
  718. on editor:>EmacsIndentUnder() {
  719.    // SmartTab
  720.    .TopView.Position.Align(1);
  721. }
  722.  
  723. //
  724. // Begins incremental searching of current buffer.
  725. //
  726. declare EmacsISearchKbd = NULL;
  727. declare EmacsISearchString = "";
  728. declare EmacsISearchDirection = SEARCH_FORWARD;
  729.  
  730. on editor:>EmacsIncrementalSearch(declare direction) {
  731.  
  732.    if (EmacsISearchKbd == NULL) {
  733.        EmacsISearchKbd = new Keyboard(false);      // not transparent
  734.        EmacsISearchKbd.Assign("<Minus>","editor.EmacsISearchMinus();");
  735.        EmacsISearchKbd.Assign("<Space>","editor.EmacsISearchSpace();");
  736.        EmacsISearchKbd.Assign("<Backspace>","editor.EmacsISearchBackspace();");
  737.        EmacsISearchKbd.Assign("<Ctrl-g>","IDE.KeyboardManager.SendKeys(\"{VK_ESCAPE}\");");
  738.        EmacsISearchKbd.Assign("<Ctrl-r>","editor.EmacsISearchBackward();");
  739.        EmacsISearchKbd.Assign("<Ctrl-s>","editor.EmacsISearchForward();");
  740.        EmacsISearchKbd.DefaultAssignment = "editor.EmacsISearchKey();";
  741.    }
  742.  
  743.    if (initialized(direction))
  744.       EmacsISearchDirection = direction;
  745.    else {
  746.        if (.SearchOptions.GoForward)
  747.           EmacsISearchDirection = SEARCH_FORWARD;
  748.        else
  749.           EmacsISearchDirection = SEARCH_BACKWARD;
  750.    }
  751.  
  752.    declare keySequence = IDE.KeyboardManager.GetKeyboard("Desktop").GetKeySequence("IDE.SearchSearchAgain();");
  753.    EmacsISearchKbd.Assign(keySequence,"editor.EmacsISearchEndAndSearchAgain();");
  754.  
  755.    IDE.KeyboardManager.Push(EmacsISearchKbd, "Editor", false);
  756.    bPopEditorKeyboard = true;
  757.    EmacsISearchString = "";
  758.    .EmacsISearchDisplayStatus();
  759. }
  760.  
  761. //
  762. // Performs incremental searching of current buffer.
  763. //
  764. on editor:>EmacsISearch(declare acKey) {
  765.  
  766.    declare ep = .TopView.Position;
  767.    declare sKey = new String(acKey);
  768.    sKey = sKey.SubString(1, 1);
  769.  
  770.    if ((IDE.KeyboardManager.KeyboardFlags & 0x03) && // Shift is pressed...
  771.        sKey.Character > 96 &&                        // It's between lower case 'a'
  772.        sKey.Character < 123)                         // and a 'z'
  773.        sKey.Character -= 32;
  774.  
  775.    // Move the cursor back before the highlight to search again from the
  776.    // begining of the highlight when searching forward.
  777.    if (EmacsISearchDirection == SEARCH_FORWARD)
  778.       ep.MoveRelative(0,-(new String(EmacsISearchString).Length));
  779.  
  780.    // Add the new key to the search string.
  781.    EmacsISearchString = EmacsISearchString + sKey.Text;
  782.  
  783.    if (EmacsISearchDirection == SEARCH_BACKWARD)
  784.       ep.MoveRelative(0,new String(EmacsISearchString).Length);
  785.  
  786.    // Search for the search string...
  787.    // If this fails go back to the previous search string and
  788.    //   search for the last known successful string.
  789.    if (!.EmacsISearchAgain()) {
  790.       declare String CS(EmacsISearchString);
  791.       EmacsISearchString = CS.SubString(0, CS.Length - 1).Text;
  792.       ep.Search(EmacsISearchString, .SearchOptions.CaseSensitive, true, EmacsISearchDirection,BRIEF_RE);
  793.    }
  794.  
  795.    .SearchOptions.SearchText = EmacsISearchString;
  796.  
  797.    .EmacsISearchDisplayStatus();
  798. }
  799.  
  800.  
  801. on editor:>EmacsISearchBackward() {
  802.    if (EmacsISearchDirection == SEARCH_BACKWARD)
  803.       .EmacsISearchAgain(true);
  804.    else
  805.       {
  806.        EmacsISearchDirection = SEARCH_BACKWARD;
  807.        .EmacsISearchAgain(true);
  808.        .EmacsISearchAgain(true);
  809.       }
  810.    .EmacsISearchDisplayStatus();
  811. }
  812.  
  813. on editor:>EmacsISearchDisplayStatus() {
  814.    if (EmacsISearchDirection == SEARCH_FORWARD)
  815.       IDE.StatusBar = "I-Search (forward) for:" + EmacsISearchString;
  816.    else
  817.       IDE.StatusBar = "I-Search (backward) for:" + EmacsISearchString;
  818. }
  819.  
  820.  
  821. on editor:>EmacsISearchForward() {
  822.    if (EmacsISearchDirection == SEARCH_FORWARD)
  823.       .EmacsISearchAgain(true);
  824.    else
  825.       {
  826.        EmacsISearchDirection = SEARCH_FORWARD;
  827.        .EmacsISearchAgain(true);
  828.        .EmacsISearchAgain(true);
  829.       }
  830.    .EmacsISearchDisplayStatus();
  831. }
  832.  
  833. on editor:>EmacsISearchAgain(declare bStep) {
  834.  
  835.    declare ep = .TopView.Position;
  836.  
  837.    declare result = ep.Search(EmacsISearchString, .SearchOptions.CaseSensitive, true, EmacsISearchDirection,BRIEF_RE);
  838.  
  839.    if (!result) {
  840.       if (bStep) {
  841.          if (EmacsISearchDirection == SEARCH_FORWARD)
  842.             ep.MoveRelative(0,-(new String(EmacsISearchString).Length));
  843.          else
  844.             ep.MoveRelative(0,new String(EmacsISearchString).Length);
  845.  
  846.          ep.Search(EmacsISearchString, .SearchOptions.CaseSensitive, true, EmacsISearchDirection,BRIEF_RE);
  847.       }
  848.     IDE.MessageBeep();
  849.    }
  850.  
  851.  return result;
  852. }
  853.  
  854.  
  855. //
  856. // Undoes the last incremental search.
  857. //
  858.  
  859. on editor:>EmacsISearchBackspace() {
  860.  
  861.    declare ep = .TopView.Position;
  862.  
  863.    // Move the cursor back before the highlight to search again from the
  864.    // begining of the highlight when searching forward.
  865.    if (EmacsISearchDirection == SEARCH_FORWARD)
  866.       ep.MoveRelative(0,-(new String(EmacsISearchString).Length));
  867.    else
  868.       ep.MoveRelative(0,new String(EmacsISearchString).Length);
  869.  
  870.    declare String CS(EmacsISearchString);
  871.  
  872.    if (CS.Length <= 1) {
  873.       EmacsISearchString = "";
  874.       ep.Move(ep.Row, ep.Column);
  875.    } else {
  876.       EmacsISearchString = CS.SubString(0, CS.Length - 1).Text;
  877.       .EmacsISearchAgain();
  878.    }
  879.  
  880.    .EmacsISearchDisplayStatus();
  881. }
  882.  
  883. //
  884. // Ends incremental searching and performs search again.
  885. //
  886. on editor:>EmacsISearchEndAndSearchAgain() {
  887.  
  888.    IDE.KeyboardManager.SendKeys("{VK_ESCAPE}");
  889.    IDE.EmacsSearchSearchAgain();
  890. }
  891.  
  892. //
  893. // Processes general keys.
  894. //
  895.  
  896. on editor:>EmacsISearchKey() {
  897.  
  898.    declare nLastKeyProcessed = IDE.KeyboardManager.LastKeyProcessed;
  899.  
  900.    if ((nLastKeyProcessed < 28) || (nLastKeyProcessed > 127)) {
  901.  
  902.       IDE.KeyboardManager.Pop("Editor");
  903.       bPopEditorKeyboard = false;
  904.  
  905.       IDE.StatusBar = "I-Search ended";
  906.       return;
  907.    }
  908.  
  909.    .EmacsISearch(IDE.KeyboardManager.CodeToKey(nLastKeyProcessed));
  910. }
  911.  
  912. on editor:>EmacsISearchMinus() {
  913.  .EmacsISearch("<->");
  914. }
  915.  
  916. on editor:>EmacsISearchSpace() {
  917.  .EmacsISearch("< >");
  918. }
  919.  
  920. on editor:>EmacsExchangePointAndMark() {
  921.    declare ev = .TopView;
  922.    declare ep = ev.Position;
  923.  
  924.    declare nPointRow = ep.Row;
  925.    declare nPointColumn = ep.Column;
  926.  
  927.    ev.BookmarkGoto(EMACS_MARK);
  928.  
  929.    declare nMarkRow = ep.Row;
  930.    declare nMarkColumn = ep.Column;
  931.  
  932.    ep.Move(nPointRow,nPointColumn);
  933.  
  934.    ev.BookmarkRecord(EMACS_MARK);
  935.  
  936.    ep.Move(nMarkRow, nMarkColumn);
  937. }
  938.  
  939. on editor:>EmacsFindFile() {
  940. }
  941.  
  942. //
  943. // Move backwards one paragraph.
  944. //
  945. on editor:>EmacsForwardParagraph() {
  946.  
  947.    declare bBlock = FALSE;
  948.    declare eb = .BlockExists();
  949.    declare ep = .TopView.Position;
  950.  
  951.    if (eb != NULL) {
  952.       bBlock = TRUE;
  953.    }
  954.  
  955.    if (ep.Column == 1 && ep.IsWhiteSpace)
  956.       ep.MoveRelative(1,0);
  957.    else
  958.       ep.Move(0,1);
  959.  
  960.    while (ep.Row != ep.LastRow) {
  961.       if (ep.IsWhiteSpace) {
  962.          break;
  963.       }
  964.       ep.MoveRelative(1,0);
  965.    }
  966.  
  967.    if (bBlock) {
  968.       eb.End();
  969.    }
  970. }
  971.  
  972. //
  973. // Using EMACS behavior to align this line with the previous non-blank
  974. // line.
  975. //
  976. on editor:>EmacsIndentPrevious() {
  977.  
  978.    declare ep = .TopView.Position;
  979.  
  980.    if (ep.Row != 1) {
  981.       ep.Save();
  982.       ep.Move(ep.Row-1,1);
  983.       ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
  984.       declare c = ep.Column;
  985.       ep.Restore();
  986.  
  987.       if (ep.Column < c)
  988.          {
  989.           declare eb = .BlockExists();
  990.           if (eb == NULL)
  991.              eb = .TopView.Block;
  992.           eb.Save();
  993.           ep.Save();
  994.           eb.Begin();
  995.           ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
  996.           eb.End();
  997.           eb.Delete();
  998.           eb.Restore();
  999.           ep.Restore();
  1000.           return ep.Align(1);
  1001.          }
  1002.    }
  1003.  
  1004.   return ep.InsertCharacter('\t');
  1005. }
  1006.  
  1007. on editor:>EmacsKillLine() {
  1008.    ess.SetKillBufferContents(.DeleteToEOL(TRUE),.TopView.Position,false);
  1009. }
  1010.  
  1011. on editor:>EmacsKillLevel() {
  1012. }
  1013.  
  1014. //
  1015. // Move the cursor down one page, extending the block.
  1016. //
  1017. on editor:>EmacsPageDown() {
  1018.    declare ep = .TopView.Position;
  1019.    declare eb = .BlockExists();
  1020.  
  1021.    if (eb != NULL) {
  1022.       ep.Save();
  1023.       eb.Save();
  1024.    }
  1025.  
  1026.    .TopView.PageDown();
  1027.    .TopView.Scroll(-1);
  1028.    .EmacsLineUp();
  1029.  
  1030.    if (eb != NULL) {
  1031.       declare row = ep.Row;
  1032.       declare column = ep.Column;
  1033.       ep.Restore();
  1034.       eb.Restore();
  1035.       eb.Extend(row, column);
  1036.    }
  1037. }
  1038.  
  1039. //
  1040. // Move the cursor up one page, extending the block.
  1041. //
  1042. on editor:>EmacsPageUp() {
  1043.    declare ep = .TopView.Position;
  1044.    declare eb = .BlockExists();
  1045.  
  1046.    if (eb != NULL) {
  1047.       ep.Save();
  1048.       eb.Save();
  1049.    }
  1050.  
  1051.    .TopView.PageUp();
  1052.    .TopView.Scroll(1);
  1053.    .EmacsLineDown();
  1054.  
  1055.    if (eb != NULL) {
  1056.       declare row = ep.Row;
  1057.       declare column = ep.Column;
  1058.       ep.Restore();
  1059.       eb.Restore();
  1060.       eb.Extend(row, column);
  1061.    }
  1062. }
  1063.  
  1064. //
  1065. // Using EMACS behavior mark the current word to the right.
  1066. //
  1067. on editor:>EmacsForwardWord() {
  1068.  
  1069.    declare ep = .TopView.Position;
  1070.    declare eb = .BlockExists();
  1071.    declare nRow = ep.Row;
  1072.    declare nColumn = ep.Column;
  1073.  
  1074.    if (eb != NULL) {
  1075.       ep.Save();
  1076.       eb.Save();
  1077.    }
  1078.  
  1079.    do {
  1080.        ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE | SKIP_STREAM);
  1081.        ep.MoveCursor(SKIP_RIGHT | SKIP_NONWORD | SKIP_STREAM);
  1082.    } while (!ep.IsWordCharacter && ep.Row != ep.LastRow);
  1083.  
  1084.    ep.MoveCursor(SKIP_RIGHT | SKIP_WORD);
  1085.  
  1086.    if (eb != NULL) {
  1087.       declare row = ep.Row;
  1088.       declare column = ep.Column;
  1089.       ep.Restore();
  1090.       eb.Restore();
  1091.       eb.Extend(row, column);
  1092.    }
  1093. }
  1094.  
  1095.  
  1096. on editor:>EmacsOneWindow() {
  1097.  
  1098.    declare ev = .TopView;
  1099.  
  1100.    if (ev != NULL) {
  1101.        declare ew = ev.Window;
  1102.        if (ew != NULL) {
  1103.          ew.OneView(ev);
  1104.        }
  1105.    }
  1106. }
  1107.  
  1108. on editor:>EmacsDeleteView() {
  1109.  
  1110.    declare ev = .TopView;
  1111.  
  1112.    if (ev != NULL) {
  1113.        declare ew = ev.Window;
  1114.        if (ew != NULL) {
  1115.          ew.RemoveView(ev);
  1116.        }
  1117.    }
  1118. }
  1119.  
  1120.  
  1121.  
  1122. //
  1123. // Using EMACS behavior cut block.
  1124. //
  1125. on editor:>EmacsKillRegion() {
  1126.    // declare variables.
  1127.    declare eb = .BlockExists();
  1128.    declare ep = .TopView.Position;
  1129.  
  1130.    if (ess.nKeysProcessedYankPop == IDE.KeyboardManager.KeysProcessed - 1) {
  1131.       return .EmacsYankPop(true);
  1132.    }
  1133.  
  1134.    if (eb != NULL) {
  1135.       // Cut the region.
  1136.       ess.SetKillBufferContents(eb.Text,ep,true);
  1137.       RemoveBlock(eb);
  1138.    } else {
  1139.       declare ev = .TopView;
  1140.       eb = ev.Block;
  1141.  
  1142.       ep.Save();
  1143.       ev.BookmarkGoto(EMACS_MARK);
  1144.       eb.Begin();
  1145.       ep.Restore();
  1146.       eb.End();
  1147.  
  1148.       if (eb.Size) {
  1149.          ess.SetKillBufferContents(eb.Text,ep,true);
  1150.          RemoveBlock(eb);
  1151.       }
  1152.  
  1153.     ResetBlock(eb);
  1154.    }
  1155. }
  1156.  
  1157. on editor:>EmacsQuotedInsert() {
  1158. }
  1159.  
  1160. //
  1161. // Using EMACS behavior begin marking.
  1162. //
  1163. on editor:>EmacsSetMark(blockOff) {
  1164.  
  1165.    if(blockOff){
  1166.       if(.BlockExists()){
  1167.          ResetBlock(EXCLUSIVE_BLOCK);
  1168.          IDE.StatusBar = "Mark Removed";
  1169.       }
  1170.       return;
  1171.    }
  1172.  
  1173.    declare eb = .TopView.Block;
  1174.    eb.Reset();
  1175.    eb.Begin();
  1176.    SetBlockStyle(EXCLUSIVE_BLOCK);
  1177.    .TopView.BookmarkRecord(EMACS_MARK);
  1178.    eb.Hide = ess.bTransparent;
  1179.    IDE.StatusBar = "Mark Set";
  1180. }
  1181.  
  1182. on editor:>EmacsShrinkWindow() {
  1183.    IDE.SetWindowState(SW_RESTORE);
  1184. }
  1185.  
  1186. on editor:>EmacsShrinkWindowHorizontal() {
  1187. }
  1188.  
  1189. //
  1190. // Change the case of the current word.
  1191. //
  1192. on editor:>_EmacsSetCase(upperCase) {
  1193.    if (.BlockExists())
  1194.       ResetBlock(EXCLUSIVE_BLOCK);
  1195.  
  1196.    if (!.TopView.Position.IsWordCharacter) {
  1197.       .EmacsForwardWord();
  1198.       .EmacsBackwardWord();
  1199.    }
  1200.  
  1201.    BeginBlock(EXCLUSIVE_BLOCK);
  1202.    .EmacsForwardWord();
  1203.    declare eb = EndBlock();
  1204.    if (upperCase)
  1205.       eb.UpperCase();
  1206.    else
  1207.       eb.LowerCase();
  1208.    ResetBlock(EXCLUSIVE_BLOCK);
  1209. }
  1210.  
  1211. //
  1212. // Using EMACS behavior upper or lower the case of the current word.
  1213. //
  1214. on editor:>EmacsUpperWord() {
  1215.    ._EmacsSetCase(TRUE);                  // Change word to UPPER CASE
  1216. }
  1217.  
  1218. on editor:>EmacsLowerWord() {
  1219.    ._EmacsSetCase(FALSE);                 // Change word to lower case
  1220. }
  1221.  
  1222. on editor:>EmacsLineDown() {
  1223.    .ModalMoveRelative(1, 0);
  1224.    .EmacsSetPreferredColumn();
  1225. }
  1226.  
  1227. on editor:>EmacsLineUp() {
  1228.    .ModalMoveRelative(-1, 0);
  1229.    .EmacsSetPreferredColumn();
  1230. }
  1231.  
  1232. on editor:>EmacsSetPreferredColumn() {
  1233.  
  1234.    declare ep = .TopView.Position;
  1235.    declare String sLine(ep.Read());
  1236.    declare nLineLength = sLine.Length + ep.Column;
  1237.  
  1238.    if (ess.nPreferredColumn > ep.Column && ess.nPreferredColumn < nLineLength)
  1239.        .ModalMoveRelative(0, ess.nPreferredColumn - ep.Column);
  1240.    else if (ess.nPreferredColumn > ep.Column )
  1241.        .ModalMoveRelative(0, nLineLength - ep.Column);
  1242. }
  1243.  
  1244. //
  1245. // Cancel current operation.
  1246. //
  1247. on editor:>EmacsSetKeyAbort(declare acKeyName) {
  1248.    if (initialized(acKeyName))
  1249.       IDE.KeyboardManager.ScriptAbortKey = acKeyName;
  1250. }
  1251.  
  1252. on editor:>EmacsSetReplace() {
  1253.  
  1254.    declare key = IDE.KeyboardManager.CodeToKey(IDE.KeyboardManager.LastKeyProcessed);
  1255.  
  1256.    if (key == "<Shift-Alt-7>" || key == "<Shift-7>") {
  1257.     .SearchOptions.RegularExpression = FALSE;
  1258.     .SearchOptions.PromptOnReplace = FALSE;
  1259.    } else if (key == "<Shift-Alt-5>" || key == "<Shift-5>") {
  1260.     .SearchOptions.RegularExpression = FALSE;
  1261.     .SearchOptions.PromptOnReplace = TRUE;
  1262.    } else if (key == "<Shift-Alt-8>" || key == "<Shift-8>" || key == "<Keypad-*>" ) {
  1263.     .SearchOptions.RegularExpression = TRUE;
  1264.     .SearchOptions.PromptOnReplace = TRUE;
  1265.    }
  1266. }
  1267.  
  1268. on editor:>EmacsSetSearch() {
  1269.  
  1270.    declare key = IDE.KeyboardManager.CodeToKey(IDE.KeyboardManager.LastKeyProcessed);
  1271.  
  1272.    if (key == "<Ctrl-Alt-r>" || key == "<Ctrl-r>" || key == "<Shift-Ctrl-r>" || key == "<Shift-Ctrl-Alt-r>") {
  1273.       .SearchOptions.GoForward = FALSE;
  1274.       .SearchOptions.RegularExpression = TRUE;
  1275.    } else {
  1276.     .SearchOptions.GoForward = TRUE;
  1277.     .SearchOptions.RegularExpression = TRUE;
  1278.    }
  1279.  
  1280. }
  1281.  
  1282. on editor:>EmacsToIndentation() {
  1283.    declare ep = .TopView.Position;
  1284.    ep.MoveBOL();
  1285.    ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE | SKIP_STREAM);
  1286. }
  1287.  
  1288. //
  1289. // Using EMACS behavior swap characters.
  1290. //
  1291. on editor:>EmacsTransposeCharacters() {
  1292.    // Get the line for positioning information.
  1293.    declare line = new String(.GetLine());
  1294.  
  1295.    // If this number of characters aren't available just end (Two
  1296.    // characters and line termination).
  1297.    if (line.Length > 4) {
  1298.       // declare variables.
  1299.       declare ep = .TopView.Position;
  1300.  
  1301.       // Save cursor position.
  1302.       ep.Save();
  1303.  
  1304.       // Check for past EOL position.
  1305.       if (ep.Column == line.Length-1)
  1306.          ep.MoveRelative(0,-2);
  1307.       else
  1308.          ep.MoveRelative(0,-1);
  1309.  
  1310.       // Get the current position character.
  1311.       declare c = ep.Character;
  1312.  
  1313.       // Delete the current position character.
  1314.       ep.Delete(1);
  1315.  
  1316.       // Insert new character after what used to be the next
  1317.       // character.
  1318.       ep.MoveRelative(0,1);
  1319.       ep.InsertCharacter(c);
  1320.  
  1321.       // Put back the cursor position
  1322.       ep.Restore();
  1323.    }
  1324. }
  1325.  
  1326. //
  1327. // Using EMACS behavior swap words.
  1328. //
  1329. on editor:>EmacsTransposeWords() {
  1330.    declare ep = .TopView.Position;
  1331.    declare eb = .TopView.Block;
  1332.  
  1333.    if (ep.IsWordCharacter && ep.Column != 1)
  1334.       .EmacsBackwardWord();
  1335.  
  1336.    .EmacsBackwardWord();
  1337.  
  1338.    .TopView.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  1339.    BeginBlock(EXCLUSIVE_BLOCK);
  1340.    .EmacsForwardWord();
  1341.    EndBlock();
  1342.  
  1343.    declare txtWord1 = eb.Text;
  1344.    eb.Delete();
  1345.    .TopView.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  1346.  
  1347.    BeginBlock(EXCLUSIVE_BLOCK);
  1348.    .EmacsForwardWord();
  1349.    .EmacsBackwardWord();
  1350.    EndBlock();
  1351.  
  1352.    declare txtWord2 = eb.Text;
  1353.    eb.Delete();
  1354.    .TopView.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  1355.  
  1356.    BeginBlock(EXCLUSIVE_BLOCK);
  1357.    .EmacsForwardWord();
  1358.    EndBlock();
  1359.  
  1360.    declare txtWord3 = eb.Text;
  1361.    eb.Delete();
  1362.    .TopView.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  1363.  
  1364.    ep.InsertText(txtWord3);
  1365.    ep.Save();
  1366.    ep.InsertText(txtWord2);
  1367.    ep.InsertText(txtWord1);
  1368.  
  1369.    ep.Restore();
  1370.    ResetBlock();
  1371. }
  1372.  
  1373. //
  1374. // Using EMACS behavior swap lines.
  1375. //
  1376. on editor:>EmacsTransposeLines() {
  1377.    // declare variables.
  1378.    declare ev = .TopView;
  1379.    declare eb = ev.Block;
  1380.    declare ep = ev.Position;
  1381.  
  1382.    // Get previous line and delete it.
  1383.    ep.MoveRelative(-1,0);
  1384.    declare txt = .GetLine();
  1385.    .DeleteLine();
  1386.  
  1387.    // EOL only moves to the end of the text.
  1388.    ep.MoveEOL();
  1389.  
  1390.    // Now move past the new line character.
  1391.    ep.MoveCursor(SKIP_RIGHT | SKIP_STREAM);
  1392.  
  1393.    // Insert new text.
  1394.    ep.InsertText(txt);
  1395.  
  1396.    // Position will always be on the second line at the begining.
  1397.    ep.MoveBOL();
  1398.    ep.MoveRelative(-1,0);
  1399. }
  1400.  
  1401. //
  1402. // Write out block.
  1403. //
  1404. on editor:>EmacsWriteRegion() {
  1405.    declare eb = .BlockExists();
  1406.  
  1407.    if (eb != NULL) {
  1408.       eb.SaveToFile();
  1409.       return;
  1410.    }
  1411. }
  1412.  
  1413. //
  1414. // Perform Yank paste operation.
  1415. //
  1416. on editor:>EmacsYank(declare popBuffer) {
  1417.    declare ev = .TopView;
  1418.    declare ep = ev.Position;
  1419.  
  1420.    if (!initialized(popBuffer)) {
  1421.        popBuffer = FALSE;
  1422.    }
  1423.  
  1424.    ep.Save();
  1425.    ep.InsertText(ess.YankKillBufferContents(ep, popBuffer));
  1426.    ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  1427.    ep.Restore();
  1428.    ev.BookmarkRecord(EMACS_MARK);
  1429.    ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  1430.    ess.nKeysProcessedYankPop = IDE.KeyboardManager.KeysProcessed;
  1431. }
  1432.  
  1433. //
  1434. // Perform YankPop paste operation.
  1435. //
  1436. on editor:>EmacsYankPop(declare bNoYank) {
  1437.    if (ess.nKeysProcessedYankPop == IDE.KeyboardManager.KeysProcessed - 1) {
  1438.       // We just yanked or yankPopped, replace what we yanked with the
  1439.       // next yank pop.
  1440.       declare ev = .TopView;
  1441.       declare ep = ev.Position;
  1442.       declare eb = ev.Block;
  1443.  
  1444.       ResetBlock(EXCLUSIVE_BLOCK);
  1445.       eb.End();
  1446.       ev.BookmarkGoto(EMACS_MARK);
  1447.       eb.Begin();
  1448.       RemoveBlock(eb,TRUE);
  1449.       if (!initialized(bNoYank))
  1450.           .EmacsYank(TRUE);
  1451.    }
  1452. }
  1453.  
  1454. on editor:>ViewActivated(newEditView) {
  1455.  
  1456.    // Reset Epsilon kill append.
  1457.    ess.nKeysProcessedKill = 0;
  1458.  
  1459.    // Check for new clipboard content.
  1460.    if (ess.nClipboardToken != newEditView.Position.GetClipboardToken()) {
  1461.       ess.nClipboardToken = newEditView.Position.GetClipboardToken();
  1462.       declare sText = new String(newEditView.Position.GetClipboard());
  1463.       if (sText.Length)
  1464.          ess.SetKillBufferContents(sText.Text,NULL,false);
  1465.    }
  1466.  
  1467.    // Perform existing behaviour
  1468.    pass(newEditView);
  1469. }
  1470.  
  1471. //
  1472. // Begins switching buffers
  1473. //
  1474. declare EmacsSelectBufferKbd = NULL;
  1475. declare ebCurrentSelectionBuffer = NULL;
  1476.  
  1477. on editor:>EmacsSelectBuffer()
  1478. {
  1479.    if (EmacsSelectBufferKbd == NULL) {
  1480.        EmacsSelectBufferKbd = new Keyboard(FALSE);      // not transparent
  1481.        EmacsSelectBufferKbd.Assign("<Down>","editor.EmacsSelectBufferDown();");
  1482.        EmacsSelectBufferKbd.Assign("<Up>","editor.EmacsSelectBufferUp();");
  1483.        EmacsSelectBufferKbd.Assign("<Enter>","editor.EmacsSelectBufferEnter();");
  1484.        EmacsSelectBufferKbd.DefaultAssignment = "editor.EmacsSelectBufferEnd(true);";
  1485.    }
  1486.  
  1487.         if (initialized(.TopBuffer)) {
  1488.                  if (!initialized(.TopBuffer.PriorBuffer()) && !initialized(.TopBuffer.NextBuffer())) {
  1489.                           IDE.StatusBar = "Only one buffer.";
  1490.                  } else {
  1491.                          ebCurrentSelectionBuffer = .TopBuffer;
  1492.                          IDE.KeyboardManager.Push(EmacsSelectBufferKbd, "Editor", FALSE);
  1493.           bPopEditorKeyboard = true;
  1494.  
  1495.                          if (initialized(.TopBuffer.PriorBuffer()))
  1496.                                   ebCurrentSelectionBuffer = .TopBuffer.PriorBuffer();
  1497.                          IDE.StatusBar = "Select Buffer: " + ebCurrentSelectionBuffer.FullName;
  1498.                  }
  1499.         } else
  1500.                 IDE.StatusBar = "No buffers loaded.";
  1501. }
  1502.  
  1503. on editor:>EmacsSelectBufferDown() {
  1504.         declare curView = .TopView;
  1505.         if (ebCurrentSelectionBuffer != NULL) {
  1506.                 ebCurrentSelectionBuffer = ebCurrentSelectionBuffer.NextBuffer();
  1507.         }
  1508.         IDE.StatusBar = "Select Buffer: " + ebCurrentSelectionBuffer.FullName;
  1509. }
  1510.  
  1511. on editor:>EmacsSelectBufferUp() {
  1512.         if (ebCurrentSelectionBuffer != NULL) {
  1513.                 ebCurrentSelectionBuffer = ebCurrentSelectionBuffer.PriorBuffer();
  1514.         }
  1515.         IDE.StatusBar = "Select Buffer: " + ebCurrentSelectionBuffer.FullName;
  1516. }
  1517.  
  1518. on editor:>EmacsSelectBufferEnter() {
  1519.         declare curView = .TopView;
  1520.  
  1521.         if (initialized(curView)) {
  1522.                 curView.Attach(ebCurrentSelectionBuffer);
  1523.         IDE.StatusBar = ebCurrentSelectionBuffer.FullName, " Selected.";
  1524.         }
  1525.  
  1526.   .EmacsSelectBufferEnd();
  1527. }
  1528.  
  1529. on editor:>EmacsSelectBufferEnd(declare bNoSelection) {
  1530.  
  1531.   if (initialized(bNoSelection))
  1532.      if (bNoSelection)
  1533.         IDE.StatusBar = "Select buffer cancelled.";
  1534.  
  1535.   IDE.KeyboardManager.Pop("Editor");
  1536.   bPopEditorKeyboard = false;
  1537. }
  1538.